package com.ruoyi.common.core.enums;

public enum CurTypeEnum {
    //这里指的离岸人名币
    RMB(10, "人民币", CurrencyEnum.CNH),
    HONGKONG_DOLLAR(20, "港币", CurrencyEnum.HKD),
    DOLLAR(30, "美金", CurrencyEnum.USD),
    dollar_a(40, "澳元", CurrencyEnum.AUD),
    EUR(50, "欧元", CurrencyEnum.EUR),
    JPY(60, "日元", CurrencyEnum.JPY),

    NZD(70, "纽币", CurrencyEnum.NZD)

    ;

    private final Integer code;
    private final String name;

    private final CurrencyEnum currencyEnum;

    CurTypeEnum(Integer code, String name, CurrencyEnum currencyEnum) {
        this.code = code;
        this.name = name;
        this.currencyEnum = currencyEnum;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {

        return name;
    }
    public CurrencyEnum getCurrencyEnum() {
        return currencyEnum;
    }

    public static String getNameByCode(Integer code) {
        for (CurTypeEnum item : CurTypeEnum.values()) {
            if (item.getCode().equals(code)) {
                return item.getName();
            }
        }
        return "";
    }

    public static Integer getCodeByName(String name) {
        for (CurTypeEnum item : CurTypeEnum.values()) {
            if (item.getName().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    public static CurTypeEnum parseByCode(Integer code) {
        for (CurTypeEnum item : CurTypeEnum.values()) {
            if (item.getCode().equals(code)) {
                return item;
            }
        }
        return null;
    }

    public static CurTypeEnum parseByCurrencyCode(String currencyCode){
        if (CurrencyEnum.CNY.getCode().equals(currencyCode))return CurTypeEnum.RMB;
        if (CurrencyEnum.HKD.getCode().equals(currencyCode))return CurTypeEnum.HONGKONG_DOLLAR;
        if (CurrencyEnum.USD.getCode().equals(currencyCode))return CurTypeEnum.DOLLAR;
        if (CurrencyEnum.AUD.getCode().equals(currencyCode))return CurTypeEnum.dollar_a;
        if (CurrencyEnum.EUR.getCode().equals(currencyCode))return CurTypeEnum.EUR;
        if (CurrencyEnum.JPY.getCode().equals(currencyCode))return CurTypeEnum.JPY;
        return null;
    }

}
